package com.edu.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.Arrays;

/**
 * ClassName:IndexController
 * Package:com.edu.controller
 * Description:
 * Date:2020/5/25 18:47
 * User: snow
 */

// 在template目录下的所有页面，只能通过controller来进行跳转访问
// 需要模板引擎的支持 thymeleaf
@Controller
public class IndexController {
	@RequestMapping("/index")
	public ModelAndView index() {
		// ModelAndView必须new
		ModelAndView mav = new ModelAndView();
		mav.addObject("msg","this is a ModelAndView message.");
		// 设置路径名,ModelAndView会自动寻址
		mav.setViewName("index");
		// 返回ModelAndView实例化对象
		return mav;
	}

	@RequestMapping("/test")
	public String test(Model model) {
		model.addAttribute("msg","<h1>this is a Model test message.</h1>");
		model.addAttribute("users", Arrays.asList("snow","Alice","Ajax"));
		// 返回跳转路径
		return "index";
	}
}
